﻿namespace Sidvall.WorkItemManager.Net.Services.V1
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WorkItemAlarm : global::Sidvall.Data.ServiceDataRowBase, global::Sidvall.WorkItemManager.Data.IWorkItemAlarm
    {
        #region Public Members

        #region MaxExecutionTimeAlarmDate

        private System.Nullable<System.DateTime> _MaxExecutionTimeAlarmDate;
        partial void OnBeforeMaxExecutionTimeAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterMaxExecutionTimeAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> MaxExecutionTimeAlarmDate
        { 
            get
            {
                return _MaxExecutionTimeAlarmDate;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxExecutionTimeAlarmDate = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _MaxExecutionTimeAlarmDate);
                    OnBeforeMaxExecutionTimeAlarmDatePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxExecutionTimeAlarmDate", eventData.Value, true, true);
                        OnAfterMaxExecutionTimeAlarmDatePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxFailedExecutionAlarmDate

        private System.Nullable<System.DateTime> _MaxFailedExecutionAlarmDate;
        partial void OnBeforeMaxFailedExecutionAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterMaxFailedExecutionAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> MaxFailedExecutionAlarmDate
        { 
            get
            {
                return _MaxFailedExecutionAlarmDate;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxFailedExecutionAlarmDate = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _MaxFailedExecutionAlarmDate);
                    OnBeforeMaxFailedExecutionAlarmDatePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxFailedExecutionAlarmDate", eventData.Value, true, true);
                        OnAfterMaxFailedExecutionAlarmDatePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MaxIdleTimeAlarmDate

        private System.Nullable<System.DateTime> _MaxIdleTimeAlarmDate;
        partial void OnBeforeMaxIdleTimeAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterMaxIdleTimeAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> MaxIdleTimeAlarmDate
        { 
            get
            {
                return _MaxIdleTimeAlarmDate;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MaxIdleTimeAlarmDate = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _MaxIdleTimeAlarmDate);
                    OnBeforeMaxIdleTimeAlarmDatePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MaxIdleTimeAlarmDate", eventData.Value, true, true);
                        OnAfterMaxIdleTimeAlarmDatePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region MonitorExecutionContextId

        private int _MonitorExecutionContextId;
        partial void OnBeforeMonitorExecutionContextIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<int> eventData);
        partial void OnAfterMonitorExecutionContextIdPropertyChanged();
        public int MonitorExecutionContextId
        { 
            get
            {
                return _MonitorExecutionContextId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _MonitorExecutionContextId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<int> eventData = new Sidvall.Business.PropertyChangeEventData<int>(value, _MonitorExecutionContextId);
                    OnBeforeMonitorExecutionContextIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("MonitorExecutionContextId", eventData.Value, true, true);
                        OnAfterMonitorExecutionContextIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region SensorAlarmDate

        private System.Nullable<System.DateTime> _SensorAlarmDate;
        partial void OnBeforeSensorAlarmDatePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData);
        partial void OnAfterSensorAlarmDatePropertyChanged();
        public System.Nullable<System.DateTime> SensorAlarmDate
        { 
            get
            {
                return _SensorAlarmDate;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _SensorAlarmDate = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<System.DateTime>>(value, _SensorAlarmDate);
                    OnBeforeSensorAlarmDatePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("SensorAlarmDate", eventData.Value, true, true);
                        OnAfterSensorAlarmDatePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemId

        private System.Nullable<long> _WorkItemId;
        partial void OnBeforeWorkItemIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterWorkItemIdPropertyChanged();
        public System.Nullable<long> WorkItemId
        { 
            get
            {
                return _WorkItemId;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemId = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _WorkItemId);
                    OnBeforeWorkItemIdPropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemId", eventData.Value, true, true);
                        OnAfterWorkItemIdPropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region WorkItemName

        private string _WorkItemName;
        partial void OnBeforeWorkItemNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterWorkItemNamePropertyChanged();
        public string WorkItemName
        { 
            get
            {
                return _WorkItemName;
            }
            set
            {
                if (this.BusinessSettings.EnabledBusinessEvents == Sidvall.Business.BusinessEvents.None)
                {
                    _WorkItemName = value;
                }
                else
                {
                    Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _WorkItemName);
                    OnBeforeWorkItemNamePropertyChanged(eventData);
                    if (!eventData.Cancel)
                    {
                        LoadInstanceField("WorkItemName", eventData.Value, true, true);
                        OnAfterWorkItemNamePropertyChanged();
                    }
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowStateIsDirty

        protected override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.DataRowStateIsDirty(this);
            }
        }

        #endregion
        
        public MonitorExecutionContext MonitorExecutionContext { get; set; }
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool updateState)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.LoadInstanceField(this, fieldName, value, cascade, false, updateState);
        }

        #endregion
        #region Copy

        public WorkItemAlarm Copy()
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Copy(this);
        }
        public WorkItemAlarm Copy(Sidvall.Data.CopySettings settings)
        {
            return global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Copy(this, settings);
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemAlarm item)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Import(this, item);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemAlarm item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Import(this, item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.ValidateAsync(this).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            return await global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.ValidateAsync(this, settings).ConfigureAwait(false);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Initialize(this, settings);
        }

        #endregion

        #region IWorkItemAlarm Members

        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MaxExecutionTimeAlarmDate
        {
            get
            {
                return this._MaxExecutionTimeAlarmDate;
            }
            set
            {
                this._MaxExecutionTimeAlarmDate = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MaxFailedExecutionAlarmDate
        {
            get
            {
                return this._MaxFailedExecutionAlarmDate;
            }
            set
            {
                this._MaxFailedExecutionAlarmDate = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MaxIdleTimeAlarmDate
        {
            get
            {
                return this._MaxIdleTimeAlarmDate;
            }
            set
            {
                this._MaxIdleTimeAlarmDate = value;
            }
        }
        int global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MonitorExecutionContextId
        {
            get
            {
                return this._MonitorExecutionContextId;
            }
            set
            {
                this._MonitorExecutionContextId = value;
            }
        }
        System.Nullable<System.DateTime> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.SensorAlarmDate
        {
            get
            {
                return this._SensorAlarmDate;
            }
            set
            {
                this._SensorAlarmDate = value;
            }
        }
        System.Nullable<long> global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.WorkItemId
        {
            get
            {
                return this._WorkItemId;
            }
            set
            {
                this._WorkItemId = value;
            }
        }
        string global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.WorkItemName
        {
            get
            {
                return this._WorkItemName;
            }
            set
            {
                this._WorkItemName = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IMonitorExecutionContext global::Sidvall.WorkItemManager.Data.IWorkItemAlarm.MonitorExecutionContext
        {
            get
            {
                return this.MonitorExecutionContext;
            }
            set
            {
                this.MonitorExecutionContext = (MonitorExecutionContext)value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WorkItemAlarm()
        {
        }
        public WorkItemAlarm(bool initializeDefaultValues)
            : this(initializeDefaultValues, null, Sidvall.Business.BusinessEvents.None)
        {
        }
        public WorkItemAlarm(bool initializeDefaultValues, Sidvall.Data.DataRowState? dataRowState, Sidvall.Business.BusinessEvents enabledBusinessEvents)
            : base(dataRowState, enabledBusinessEvents)
        {
            if (initializeDefaultValues)
                global::Sidvall.WorkItemManager.SystemContextConfig.Current.EntityFacade.WorkItemAlarmManager.Initialize(this);
        }

        #endregion
    }
}